package ljl.alg.wangzheng_camp.round1.bisection;

public class _35_search_insert {
    
    /**
     * 到底啥时候用 等号
     * 啥时候用 nums.length？？
     * 不得而知！
     * */
    public int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        while (l <= r) {
            int mid = (l + r) >>> 1;
            if (nums[mid] == target) return mid;
            if (nums[mid] < target) l = mid + 1;
            else r = mid - 1;
        }
        return l;
    }
    
}
